import 'package:containerbox_study/page/flashnews/flashnews.dart';
import 'package:containerbox_study/page/mine/minepage.dart';
import 'package:containerbox_study/page/theme/themepage.dart';
import 'package:containerbox_study/page/tool/toolspage.dart';
import 'package:containerbox_study/page/toutiao/toutiaopage.dart';
import 'package:flutter/material.dart';

class AppHomePage extends StatefulWidget {
  @override
  _AppHomePageState createState() => _AppHomePageState();
}

class _AppHomePageState extends State<AppHomePage> {
  int _index = 0;

  List<Widget> _widgetList = [
    FlashNews(),
    ThemePage(),
    TouTiaoPage(),
    ToolPage(),
    MinePage()
  ];

  void _onBottomNavibarTap(index) {
    setState(() {
      _index = index;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('老虎财经'),
      ),
      body: IndexedStack(
        index: _index,
        children: _widgetList,
      ),
      bottomNavigationBar: BottomNavigationBar(
        type: BottomNavigationBarType.fixed,
        currentIndex: _index,
        onTap: _onBottomNavibarTap,
        items: [
          _navigationBarItem('快讯', 'images/tabbar_newflash_normal@2x.png',
              'images/tabbar_newflash_select@2x.png', 0),
          _navigationBarItem('专栏', 'images/tabbar_theme_normal@2x.png',
              'images/tabbar_theme_select@2x.png', 1),
          _navigationBarItem('头条', 'images/tabbar_toutiao_normal@2x.png',
              'images/tabbar_toutiao_sel@2x.png', 2),
          _navigationBarItem('工具', 'images/tabbar_hushen_normal@2x.png',
              'images/tabbar_hushen_sel@2x.png', 3),
          _navigationBarItem('我的', 'images/tabbar_wd@2x.png',
              'images/tabbar_wd_sel@2x.png', 4),
        ],
      ),
    );
  }

  BottomNavigationBarItem _navigationBarItem(
      String title, String normalIcon, String selectedIcon, int index) {
    return BottomNavigationBarItem(
        icon: index == _index
            ? Image.asset(
                selectedIcon,
                width: 32,
                height: 28,
              )
            : Image.asset(normalIcon, width: 32, height: 28),
        label: title);
  }
}
